<html>
<head>
<title>File Source for functions.array.php</title>
<link rel="stylesheet" type="text/css" href="../media/style.css">
</head>
<body>

<table border="0" cellspacing="0" cellpadding="0" height="48" width="100%">
  <tr>
    <td class="header_top">smt2</td>
  </tr>
  <tr><td class="header_line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
  <tr>
    <td class="header_menu">
        
                                    
                                                                      		  [ <a href="../classtrees_smt2.html" class="menu">class tree: smt2</a> ]
		  [ <a href="../elementindex_smt2.html" class="menu">index: smt2</a> ]
		  	    [ <a href="../elementindex.html" class="menu">all elements</a> ]
    </td>
  </tr>
  <tr><td class="header_line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="200" class="menu">
      <b>Packages:</b><br />
              <a href="../li_smt2.html">smt2</a><br />
              <a href="../li_PegasusPHP.html">PegasusPHP</a><br />
              <a href="../li_PHPMailer.html">PHPMailer</a><br />
            <br /><br />
                  
      
                </td>
    <td>
      <table cellpadding="10" cellspacing="0" width="100%" border="0"><tr><td valign="top">

<h1 align="center">Source for file functions.array.php</h1>
<p>Documentation is available at <a href="../smt2/_functions.array.php.html">functions.array.php</a></p>
<div class="src-code">
<ol><li><div class="src-line"><a name="a1"></a><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line"><a name="a2"></a><span class="src-doc">/**&nbsp;</span></div></li>
<li><div class="src-line"><a name="a3"></a><span class="src-doc">&nbsp;*&nbsp;Computes&nbsp;the&nbsp;frequency&nbsp;of&nbsp;each&nbsp;$input&nbsp;array&nbsp;member.</span></div></li>
<li><div class="src-line"><a name="a4"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc">&nbsp;&nbsp;</span><span class="src-doc-type">mixed&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-var">$input&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;input&nbsp;string&nbsp;or&nbsp;array&nbsp;of&nbsp;strings&nbsp;to&nbsp;parse&nbsp;($_POST&nbsp;vars&nbsp;are&nbsp;sent&nbsp;as&nbsp;strings)</span></div></li>
<li><div class="src-line"><a name="a5"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc">&nbsp;&nbsp;</span><span class="src-doc-type">int&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;</span><span class="src-doc-var">$threshold&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;frequencies&nbsp;(in&nbsp;percentage)&nbsp;under&nbsp;this&nbsp;$threshold&nbsp;will&nbsp;not&nbsp;be&nbsp;stored&nbsp;(default:&nbsp;1%)</span></div></li>
<li><div class="src-line"><a name="a6"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@return&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;sorted&nbsp;associative&nbsp;array&nbsp;in&nbsp;the&nbsp;form&nbsp;'[mostFrequentItem]=&gt;frequency,...,[lessFrequentItem]=&gt;frequency'</span></div></li>
<li><div class="src-line"><a name="a7"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a8"></a><span class="src-key">function&nbsp;</span><a href="../smt2/_functions.array.php.html#functionarray_frequency">array_frequency</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">,&nbsp;</span><span class="src-var">$threshold&nbsp;</span>=&nbsp;<span class="src-num">1</span><span class="src-sym">)&nbsp;</span></div></li>
<li><div class="src-line"><a name="a9"></a><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a10"></a>&nbsp;&nbsp;<span class="src-comm">//&nbsp;convert&nbsp;$input&nbsp;in&nbsp;a&nbsp;real&nbsp;PHP&nbsp;array</span></div></li>
<li><div class="src-line"><a name="a11"></a>&nbsp;&nbsp;<span class="src-var">$input&nbsp;</span>=&nbsp;<span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">))&nbsp;</span>?&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;,&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$input</span><span class="src-sym">)&nbsp;</span>:&nbsp;<span class="src-var">$input</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a12"></a>&nbsp;&nbsp;<span class="src-comm">//&nbsp;count&nbsp;occurrences&nbsp;(array&nbsp;keys&nbsp;must&nbsp;be&nbsp;strings&nbsp;or&nbsp;integers)</span></div></li>
<li><div class="src-line"><a name="a13"></a>&nbsp;&nbsp;<span class="src-var">$unique&nbsp;</span>=&nbsp;<a href="http://www.php.net/array_count_values">array_count_values</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span><span class="src-sym">;&nbsp;</span><span class="src-comm">//&nbsp;returns&nbsp;an&nbsp;associative&nbsp;array&nbsp;of&nbsp;values&nbsp;from&nbsp;$input&nbsp;as&nbsp;keys&nbsp;and&nbsp;their&nbsp;count&nbsp;as&nbsp;value.</span></div></li>
<li><div class="src-line"><a name="a14"></a>&nbsp;&nbsp;<span class="src-comm">//&nbsp;$hovered&nbsp;is&nbsp;an&nbsp;associative&nbsp;array(string&nbsp;=&gt;&nbsp;int)</span></div></li>
<li><div class="src-line"><a name="a15"></a>&nbsp;&nbsp;<span class="src-var">$unique&nbsp;</span>=&nbsp;<a href="../smt2/_functions.array.php.html#functionarray_sanitize">array_sanitize</a><span class="src-sym">(</span><span class="src-var">$unique</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a16"></a>&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a17"></a>&nbsp;&nbsp;<span class="src-comm">//&nbsp;exit&nbsp;if&nbsp;there&nbsp;are&nbsp;no&nbsp;data</span></div></li>
<li><div class="src-line"><a name="a18"></a>&nbsp;&nbsp;<span class="src-key">if&nbsp;</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-var">$unique</span><span class="src-sym">)&nbsp;</span><span class="src-key">return&nbsp;</span><span class="src-id">false</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a19"></a>&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a20"></a>&nbsp;&nbsp;<span class="src-comm">//&nbsp;compute&nbsp;sum</span></div></li>
<li><div class="src-line"><a name="a21"></a>&nbsp;&nbsp;<span class="src-var">$sum&nbsp;&nbsp;</span>=&nbsp;<a href="http://www.php.net/array_sum">array_sum</a><span class="src-sym">(</span><span class="src-var">$unique</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a22"></a>&nbsp;&nbsp;<span class="src-var">$data&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a23"></a>&nbsp;&nbsp;<span class="src-comm">//&nbsp;now&nbsp;calculate&nbsp;the&nbsp;frequency&nbsp;of&nbsp;each&nbsp;hovered&nbsp;element&nbsp;(in&nbsp;percentage)</span></div></li>
<li><div class="src-line"><a name="a24"></a>&nbsp;&nbsp;<span class="src-key">foreach&nbsp;</span><span class="src-sym">(</span><span class="src-var">$unique&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$k&nbsp;</span>=&gt;&nbsp;<span class="src-var">$value</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a25"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$frequency&nbsp;</span>=&nbsp;<a href="http://www.php.net/round">round</a><span class="src-sym">(</span><span class="src-num">100</span>*<span class="src-var">$value</span>/<span class="src-var">$sum</span><span class="src-sym">,&nbsp;</span><span class="src-num">2</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a26"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;store&nbsp;frecuencies&nbsp;above&nbsp;given&nbsp;threshold</span></div></li>
<li><div class="src-line"><a name="a27"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if&nbsp;</span><span class="src-sym">(</span><span class="src-var">$frequency&nbsp;</span>&gt;&nbsp;<span class="src-var">$threshold</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a28"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$data</span><span class="src-sym">[</span><span class="src-var">$k</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-var">$frequency</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a29"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}&nbsp;</span></div></li>
<li><div class="src-line"><a name="a30"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a31"></a>&nbsp;&nbsp;<span class="src-comm">//&nbsp;order&nbsp;by&nbsp;frecuency</span></div></li>
<li><div class="src-line"><a name="a32"></a>&nbsp;&nbsp;<a href="http://www.php.net/arsort">arsort</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a33"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a34"></a>&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$data</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a35"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a36"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a37"></a><span class="src-doc">/**&nbsp;</span></div></li>
<li><div class="src-line"><a name="a38"></a><span class="src-doc">&nbsp;*&nbsp;Removes&nbsp;empty&nbsp;items&nbsp;(both&nbsp;key&nbsp;and&nbsp;value)&nbsp;from&nbsp;an&nbsp;associative&nbsp;numeric&nbsp;array.</span></div></li>
<li><div class="src-line"><a name="a39"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc">&nbsp;&nbsp;</span><span class="src-doc-type">mixed&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-var">$input&nbsp;</span><span class="src-doc">&nbsp;&nbsp;array&nbsp;or&nbsp;string&nbsp;to&nbsp;sanitize</span></div></li>
<li><div class="src-line"><a name="a40"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@return&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-type">mixed&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sanitized&nbsp;array&nbsp;or&nbsp;string&nbsp;(used&nbsp;for&nbsp;widget&nbsp;tracking)</span></div></li>
<li><div class="src-line"><a name="a41"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a42"></a><span class="src-key">function&nbsp;</span><a href="../smt2/_functions.array.php.html#functionarray_sanitize">array_sanitize</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a43"></a><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a44"></a>&nbsp;&nbsp;<span class="src-var">$isString&nbsp;</span>=&nbsp;<span class="src-id">false</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a45"></a>&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a46"></a>&nbsp;&nbsp;<span class="src-key">if&nbsp;</span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{&nbsp;</span></div></li>
<li><div class="src-line"><a name="a47"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$input&nbsp;</span>=&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;,&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$input</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a48"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$isString&nbsp;</span>=&nbsp;<span class="src-id">true</span><span class="src-sym">;&nbsp;</span></div></li>
<li><div class="src-line"><a name="a49"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a50"></a>&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a51"></a>&nbsp;&nbsp;<span class="src-var">$temp&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;&nbsp;&nbsp;</span></div></li>
<li><div class="src-line"><a name="a52"></a>&nbsp;&nbsp;<span class="src-key">foreach&nbsp;</span><span class="src-sym">(</span><span class="src-var">$input&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$key&nbsp;</span>=&gt;&nbsp;<span class="src-var">$value</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a53"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;avoid&nbsp;buggy&nbsp;values</span></div></li>
<li><div class="src-line"><a name="a54"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$key&nbsp;</span>=&nbsp;<a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a55"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$value&nbsp;</span>=&nbsp;<a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a56"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;store&nbsp;valid&nbsp;data</span></div></li>
<li><div class="src-line"><a name="a57"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if&nbsp;</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">)&nbsp;</span>&amp;&amp;&nbsp;<span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a58"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$temp</span><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-var">$value</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a59"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a60"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a61"></a>&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a62"></a>&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-sym">(</span><span class="src-var">$isString</span><span class="src-sym">)&nbsp;</span>?&nbsp;<a href="http://www.php.net/implode">implode</a><span class="src-sym">(</span><span class="src-str">&quot;,&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$temp</span><span class="src-sym">)&nbsp;</span>:&nbsp;<span class="src-var">$temp</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a63"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a64"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a65"></a><span class="src-doc">/**&nbsp;</span></div></li>
<li><div class="src-line"><a name="a66"></a><span class="src-doc">&nbsp;*&nbsp;Convert&nbsp;null&nbsp;values&nbsp;to&nbsp;empty&nbsp;strings.&nbsp;Used&nbsp;to&nbsp;generate&nbsp;valid&nbsp;JSON&nbsp;arrays.</span></div></li>
<li><div class="src-line"><a name="a67"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc">&nbsp;&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-var">$input&nbsp;</span><span class="src-doc">&nbsp;&nbsp;array</span></div></li>
<li><div class="src-line"><a name="a68"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@return&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Parsed&nbsp;array</span></div></li>
<li><div class="src-line"><a name="a69"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a70"></a><span class="src-key">function&nbsp;</span><a href="../smt2/_functions.array.php.html#functionarray_null">array_null</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a71"></a><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a72"></a>&nbsp;&nbsp;<span class="src-key">if&nbsp;</span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a73"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$input&nbsp;</span>=&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;,&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$input</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a74"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a75"></a>&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a76"></a>&nbsp;&nbsp;<span class="src-var">$temp&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;&nbsp;</span></div></li>
<li><div class="src-line"><a name="a77"></a>&nbsp;&nbsp;<span class="src-key">foreach&nbsp;</span><span class="src-sym">(</span><span class="src-var">$input&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$key&nbsp;</span>=&gt;&nbsp;<span class="src-var">$value</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a78"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;store&nbsp;valid&nbsp;data</span></div></li>
<li><div class="src-line"><a name="a79"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$temp</span><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">))&nbsp;</span>?&nbsp;<span class="src-var">$value&nbsp;</span>:&nbsp;<span class="src-num">0</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a80"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a81"></a>&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a82"></a>&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$temp</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a83"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a84"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a85"></a><span class="src-doc">/**&nbsp;</span></div></li>
<li><div class="src-line"><a name="a86"></a><span class="src-doc">&nbsp;*&nbsp;Does&nbsp;a&nbsp;weighted&nbsp;sum&nbsp;for&nbsp;a&nbsp;given&nbsp;multidimensional&nbsp;numeric&nbsp;array&nbsp;and&nbsp;computed&nbsp;weights.</span></div></li>
<li><div class="src-line"><a name="a87"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc">&nbsp;&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-var">$input&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;multidimensional&nbsp;array&nbsp;(matrix)</span></div></li>
<li><div class="src-line"><a name="a88"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc">&nbsp;&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-var">$weights&nbsp;</span><span class="src-doc">&nbsp;&nbsp;weights</span></div></li>
<li><div class="src-line"><a name="a89"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@return&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Weighted&nbsp;sum</span></div></li>
<li><div class="src-line"><a name="a90"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@link</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;http://www.compapp.dcu.ie/~humphrys/PhD/e.html</span></div></li>
<li><div class="src-line"><a name="a91"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a92"></a><span class="src-key">function&nbsp;</span><a href="../smt2/_functions.array.php.html#functionarray_avg_weighted">array_avg_weighted</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">,&nbsp;</span><span class="src-var">$weights</span><span class="src-sym">)&nbsp;</span></div></li>
<li><div class="src-line"><a name="a93"></a><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a94"></a>&nbsp;&nbsp;<span class="src-var">$sumArray&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a95"></a>&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a96"></a>&nbsp;&nbsp;<span class="src-key">foreach&nbsp;</span><span class="src-sym">(</span><span class="src-var">$input&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$arrItem</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a97"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$sumArray</span><span class="src-sym">[</span><span class="src-sym">]&nbsp;</span>=&nbsp;<a href="../smt2/_functions.array.php.html#functionarray_avg">array_avg</a><span class="src-sym">(</span><span class="src-var">$arrItem</span><span class="src-sym">)&nbsp;</span>*&nbsp;<a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$arrItem</span><span class="src-sym">)&nbsp;</span>/&nbsp;<a href="http://www.php.net/max">max</a><span class="src-sym">(</span><span class="src-var">$weights</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a98"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a99"></a>&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a100"></a>&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$sumArray</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a101"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a102"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a103"></a><span class="src-doc">/**&nbsp;</span></div></li>
<li><div class="src-line"><a name="a104"></a><span class="src-doc">&nbsp;*&nbsp;Computes&nbsp;the&nbsp;average&nbsp;sum&nbsp;of&nbsp;a&nbsp;numeric&nbsp;array.</span></div></li>
<li><div class="src-line"><a name="a105"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc">&nbsp;&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-var">$input&nbsp;</span><span class="src-doc">&nbsp;&nbsp;array&nbsp;or&nbsp;set&nbsp;of&nbsp;arrays&nbsp;(matrix)</span></div></li>
<li><div class="src-line"><a name="a106"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@return&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-type">float&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Array&nbsp;average</span></div></li>
<li><div class="src-line"><a name="a107"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a108"></a><span class="src-key">function&nbsp;</span><a href="../smt2/_functions.array.php.html#functionarray_avg">array_avg</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a109"></a><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a110"></a>&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><a href="http://www.php.net/round">round</a><span class="src-sym">(&nbsp;</span><a href="http://www.php.net/array_sum">array_sum</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)&nbsp;</span>/&nbsp;<a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span><span class="src-sym">,&nbsp;</span><span class="src-num">2</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a111"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a112"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a113"></a><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a114"></a><span class="src-doc">&nbsp;*&nbsp;Computes&nbsp;the&nbsp;average&nbsp;sum&nbsp;of&nbsp;a&nbsp;matrix,&nbsp;assuming&nbsp;that&nbsp;each&nbsp;row&nbsp;is&nbsp;a&nbsp;numeric&nbsp;array.</span></div></li>
<li><div class="src-line"><a name="a115"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc">&nbsp;&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc-var">$matrix&nbsp;</span><span class="src-doc">a&nbsp;set&nbsp;of&nbsp;arrays&nbsp;(matrix)</span></div></li>
<li><div class="src-line"><a name="a116"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@return&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-type">float&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matrix&nbsp;average&nbsp;value</span></div></li>
<li><div class="src-line"><a name="a117"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a118"></a><span class="src-key">function&nbsp;</span><a href="../smt2/_functions.array.php.html#functionmatrix_avg">matrix_avg</a><span class="src-sym">(</span><span class="src-var">$matrix</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a119"></a><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a120"></a>&nbsp;&nbsp;<span class="src-var">$sum&nbsp;</span>=&nbsp;<span class="src-num">0</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a121"></a>&nbsp;&nbsp;<span class="src-var">$count&nbsp;</span>=&nbsp;<span class="src-num">0</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a122"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a123"></a>&nbsp;&nbsp;<span class="src-key">foreach&nbsp;</span><span class="src-sym">(</span><span class="src-var">$matrix&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$arrItem</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a124"></a>&nbsp;&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a125"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if&nbsp;</span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$arrItem</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{&nbsp;</span><span class="src-var">$arrItem&nbsp;</span>=&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;,&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$arrItem</span><span class="src-sym">)</span><span class="src-sym">;&nbsp;</span><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a126"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a127"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$sum&nbsp;</span>+=&nbsp;<a href="../smt2/_functions.array.php.html#functionarray_avg">array_avg</a><span class="src-sym">(</span><span class="src-var">$arrItem</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a128"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;note&nbsp;that&nbsp;this&nbsp;is&nbsp;an&nbsp;accumulative&nbsp;sum</span></div></li>
<li><div class="src-line"><a name="a129"></a>&nbsp;&nbsp;&nbsp;&nbsp;++<span class="src-var">$count</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a130"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a131"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a132"></a>&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><a href="http://www.php.net/round">round</a><span class="src-sym">(&nbsp;</span><span class="src-var">$sum</span>/<span class="src-var">$count</span><span class="src-sym">,&nbsp;</span><span class="src-num">2&nbsp;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a133"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a134"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a135"></a><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a136"></a><span class="src-doc">&nbsp;*&nbsp;Computes&nbsp;the&nbsp;variance&nbsp;of&nbsp;a&nbsp;numeric&nbsp;array.</span></div></li>
<li><div class="src-line"><a name="a137"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc">&nbsp;&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-var">$input&nbsp;</span><span class="src-doc">&nbsp;&nbsp;array</span></div></li>
<li><div class="src-line"><a name="a138"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@return&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-type">int&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Array&nbsp;index</span></div></li>
<li><div class="src-line"><a name="a139"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a140"></a><span class="src-key">function&nbsp;</span><a href="../smt2/_functions.array.php.html#functionarray_sd">array_sd</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a141"></a><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a142"></a>&nbsp;&nbsp;<span class="src-var">$variance&nbsp;</span>=&nbsp;<span class="src-num">0</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a143"></a>&nbsp;&nbsp;<span class="src-var">$mean&nbsp;</span>=&nbsp;<a href="../smt2/_functions.array.php.html#functionarray_avg">array_avg</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a144"></a>&nbsp;&nbsp;<span class="src-key">foreach&nbsp;</span><span class="src-sym">(</span><span class="src-var">$input&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$elem</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a145"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$variance&nbsp;</span>+=&nbsp;<span class="src-sym">(</span><span class="src-var">$elem&nbsp;</span>-&nbsp;<span class="src-var">$mean</span><span class="src-sym">)&nbsp;</span>*&nbsp;<span class="src-sym">(</span><span class="src-var">$elem&nbsp;</span>-&nbsp;<span class="src-var">$mean</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a146"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a147"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a148"></a>&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><a href="http://www.php.net/round">round</a><span class="src-sym">(&nbsp;</span><a href="http://www.php.net/sqrt">sqrt</a><span class="src-sym">(</span><span class="src-var">$variance</span>/<a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">))</span><span class="src-sym">,&nbsp;</span><span class="src-num">2&nbsp;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a149"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a150"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a151"></a><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a152"></a><span class="src-doc">&nbsp;*&nbsp;Computes&nbsp;the&nbsp;standard&nbsp;deviation&nbsp;of&nbsp;a&nbsp;matrix,&nbsp;assuming&nbsp;that&nbsp;each&nbsp;row&nbsp;is&nbsp;a&nbsp;numeric&nbsp;array.</span></div></li>
<li><div class="src-line"><a name="a153"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc">&nbsp;&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc-var">$matrix&nbsp;</span><span class="src-doc">a&nbsp;set&nbsp;of&nbsp;arrays&nbsp;(matrix)</span></div></li>
<li><div class="src-line"><a name="a154"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@return&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-type">float&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matrix&nbsp;average&nbsp;value</span></div></li>
<li><div class="src-line"><a name="a155"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a156"></a><span class="src-key">function&nbsp;</span><a href="../smt2/_functions.array.php.html#functionmatrix_sd">matrix_sd</a><span class="src-sym">(</span><span class="src-var">$matrix</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a157"></a><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a158"></a>&nbsp;&nbsp;<span class="src-var">$sd&nbsp;</span>=&nbsp;<span class="src-num">0</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a159"></a>&nbsp;&nbsp;<span class="src-var">$count&nbsp;</span>=&nbsp;<span class="src-num">0</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a160"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a161"></a>&nbsp;&nbsp;<span class="src-key">foreach&nbsp;</span><span class="src-sym">(</span><span class="src-var">$matrix&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$arrItem</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a162"></a>&nbsp;&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a163"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if&nbsp;</span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$arrItem</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{&nbsp;</span><span class="src-var">$arrItem&nbsp;</span>=&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;,&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$arrItem</span><span class="src-sym">)</span><span class="src-sym">;&nbsp;</span><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a164"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a165"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$sd&nbsp;</span>+=&nbsp;<a href="../smt2/_functions.array.php.html#functionarray_sd">array_sd</a><span class="src-sym">(</span><span class="src-var">$arrItem</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a166"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;note&nbsp;that&nbsp;we&nbsp;can&nbsp;have&nbsp;more&nbsp;than&nbsp;one&nbsp;input&nbsp;array</span></div></li>
<li><div class="src-line"><a name="a167"></a>&nbsp;&nbsp;&nbsp;&nbsp;++<span class="src-var">$count</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a168"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a169"></a>&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a170"></a>&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><a href="http://www.php.net/round">round</a><span class="src-sym">(&nbsp;</span><span class="src-var">$sd</span>/<span class="src-var">$count</span><span class="src-sym">,&nbsp;</span><span class="src-num">2&nbsp;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a171"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a172"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a173"></a><span class="src-doc">/**&nbsp;</span></div></li>
<li><div class="src-line"><a name="a174"></a><span class="src-doc">&nbsp;*&nbsp;Gets&nbsp;the&nbsp;array&nbsp;index&nbsp;that&nbsp;has&nbsp;the&nbsp;maximum&nbsp;value.</span></div></li>
<li><div class="src-line"><a name="a175"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc">&nbsp;&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-var">$input&nbsp;</span><span class="src-doc">&nbsp;&nbsp;array</span></div></li>
<li><div class="src-line"><a name="a176"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@return&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-type">int&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Array&nbsp;index</span></div></li>
<li><div class="src-line"><a name="a177"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a178"></a><span class="src-key">function&nbsp;</span><a href="../smt2/_functions.array.php.html#functionarray_argmax">array_argmax</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a179"></a><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a180"></a>&nbsp;&nbsp;<span class="src-var">$max&nbsp;</span>=&nbsp;<a href="http://www.php.net/max">max</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a181"></a>&nbsp;&nbsp;<span class="src-key">foreach&nbsp;</span><span class="src-sym">(</span><span class="src-var">$input&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$key&nbsp;</span>=&gt;&nbsp;<span class="src-var">$value</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a182"></a>&nbsp;&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a183"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if&nbsp;</span><span class="src-sym">(</span><span class="src-var">$value&nbsp;</span>==&nbsp;<span class="src-var">$max</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a184"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$maxIndex&nbsp;</span>=&nbsp;<span class="src-var">$key</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a185"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">break</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a186"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a187"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a188"></a>&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a189"></a>&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$maxIndex</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a190"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a191"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a192"></a><span class="src-doc">/**&nbsp;</span></div></li>
<li><div class="src-line"><a name="a193"></a><span class="src-doc">&nbsp;*&nbsp;Gets&nbsp;the&nbsp;array&nbsp;index&nbsp;that&nbsp;has&nbsp;the&nbsp;minimum&nbsp;value.</span></div></li>
<li><div class="src-line"><a name="a194"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc">&nbsp;&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-var">$input&nbsp;</span><span class="src-doc">&nbsp;&nbsp;array</span></div></li>
<li><div class="src-line"><a name="a195"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@return&nbsp;</span><span class="src-doc">&nbsp;</span><span class="src-doc-type">int&nbsp;</span><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Array&nbsp;index</span></div></li>
<li><div class="src-line"><a name="a196"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a197"></a><span class="src-key">function&nbsp;</span><a href="../smt2/_functions.array.php.html#functionarray_argmin">array_argmin</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a198"></a><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a199"></a>&nbsp;&nbsp;<span class="src-var">$min&nbsp;</span>=&nbsp;<a href="http://www.php.net/min">min</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a200"></a>&nbsp;&nbsp;<span class="src-key">foreach&nbsp;</span><span class="src-sym">(</span><span class="src-var">$input&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$key&nbsp;</span>=&gt;&nbsp;<span class="src-var">$value</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a201"></a>&nbsp;&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a202"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if&nbsp;</span><span class="src-sym">(</span><span class="src-var">$value&nbsp;</span>==&nbsp;<span class="src-var">$min</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a203"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$minIndex&nbsp;</span>=&nbsp;<span class="src-var">$key</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a204"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">break</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a205"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a206"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a207"></a>&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a208"></a>&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$minIndex</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a209"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a210"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a211"></a><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a212"></a><span class="src-doc">&nbsp;*&nbsp;De-nests&nbsp;nested&nbsp;arrays&nbsp;within&nbsp;the&nbsp;given&nbsp;array.</span></div></li>
<li><div class="src-line"><a name="a213"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-tag">@autor</span><span class="src-doc">&nbsp;DZone&nbsp;Snippets</span></div></li>
<li><div class="src-line"><a name="a214"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@link</span><span class="src-doc">&nbsp;&nbsp;http://snippets.dzone.com/posts/show/4660</span></div></li>
<li><div class="src-line"><a name="a215"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a216"></a><span class="src-key">function&nbsp;</span><a href="../smt2/_functions.array.php.html#functionarray_flatten">array_flatten</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a217"></a><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a218"></a>&nbsp;&nbsp;<span class="src-var">$i&nbsp;</span>=&nbsp;<span class="src-num">0</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a219"></a>&nbsp;&nbsp;<span class="src-key">while&nbsp;</span><span class="src-sym">(</span><span class="src-var">$i&nbsp;</span>&lt;&nbsp;<a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">))</span></div></li>
<li><div class="src-line"><a name="a220"></a>&nbsp;&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a221"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if&nbsp;</span><span class="src-sym">(</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">[</span><span class="src-var">$i</span><span class="src-sym">]</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a222"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.php.net/array_splice">array_splice</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">,&nbsp;</span><span class="src-var">$i</span><span class="src-sym">,&nbsp;</span><span class="src-num">1</span><span class="src-sym">,&nbsp;</span><span class="src-var">$input</span><span class="src-sym">[</span><span class="src-var">$i</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a223"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}&nbsp;</span><span class="src-key">else&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a224"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;++<span class="src-var">$i</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a225"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a226"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a227"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a228"></a>&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$input</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a229"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a230"></a><span class="src-php">?&gt;</span></div></li>
</ol>
</div>
        <div class="credit">
		    <hr />
		    Documentation generated on Thu, 30 Sep 2010 18:26:49 +0200 by <a href="http://www.phpdoc.org">phpDocumentor 1.4.1</a>
	      </div>
      </td></tr></table>
    </td>
  </tr>
</table>

</body>
</html>